
--create buttons
function trashmobs_FrameIgnoreCreateButtons()
	local buttonPrefix;
	local buttonText, buttonParent;
	
	buttonPrefix="FrameIgnoreButton";
	buttonParent=getglobal("TrashmobsIgnoreFrame");
	
	for i=1, TRM_MEMBER_LIST_MAX, 1 do
		local myButton;
		myButton=CreateFrame("Button", buttonPrefix .. i,buttonParent,"IgnoreFrameButtonTemplate");
		myButton:SetPoint("TOPLEFT","TrashmobsIgnoreFrame","TOPLEFT",14,-110 - (i *16));
		myButton:SetScript("OnClick",function(self) trashmobs_IgnoreFrameSetSelectedButton(self:GetName()) end );
		myButton:Hide();
		
		buttonText=getglobal(myButton:GetName() .. "Name");
		buttonText:SetText("");
	end
	
	
end

-- when user added a new ignored player
function trashmobs_FrameIgnoreAddPlayer(playerName)
		trashmobs_TableInsertOnce(trashmobs_settings["IGNORE_LIST"],playerName);
		trashmobs_UpdateIgnoreFrame();
end

--when Button Add is clicked
function trashmobs_FrameIgnoreButtonOKClicked()
	if(getn(trashmobs_settings["IGNORE_LIST"]) < TRM_MEMBER_LIST_MAX ) then
		TrashmobsAddIgnoreFrame:Show();
	end
end

-- when user remove 
function trashmobs_FrameIgnoreRemovePlayer(ButtonName)
	local index;
	
	index=strsub(ButtonName,strlen("FrameIgnoreButton")+1);
	table.remove(trashmobs_settings["IGNORE_LIST"],index);
	
	TRM_SELECTED_IGNORE=1;
	trashmobs_UpdateIgnoreFrame();
end

--update names
function trashmobs_UpdateIgnoreFrame()
	local myButton, myButtonText, buttonPrefix;
	
	buttonPrefix="FrameIgnoreButton";
	
	for i=1, TRM_MEMBER_LIST_MAX, 1 do
		myButtonText=getglobal("FrameIgnoreButton" .. i .. "Name");
		myButton=getglobal("FrameIgnoreButton" .. i);
		
		if(trashmobs_settings["IGNORE_LIST"][i] ~= nil) then
			myButtonText:SetText(trashmobs_settings["IGNORE_LIST"][i]);
			myButton:Show();
		else
			myButtonText:SetText("");
			myButton:Hide();
		end
		
		
		
		--Highlight
		if(myButton:GetName()==TRM_SELECTED_IGNORE) then
			myButton:LockHighlight();
		else
			myButton:UnlockHighlight();
		end
	end
end 

-- Button is  clicked
function trashmobs_IgnoreFrameSetSelectedButton(ButtonName)
	TRM_SELECTED_IGNORE=ButtonName;
	trashmobs_UpdateIgnoreFrame();
end

